﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QuestionBank
{
    public partial class Part1 : Form
    {
        public Part1()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string examType = "1";
            string parentid = txtParentID.Text.Trim();
            string questionType = txtQuestionType.Text.Trim();
            string Description = "";
            if (string.IsNullOrEmpty(questionType))
            {
                MessageBox.Show("请填写试题类型");
                return;
            }
            string dbPath = txtDB.Text.Trim();
            SQLiteDatabase db = new SQLiteDatabase(dbPath);

            string title = rtbTitle.Text.Trim().Replace('’', ' ').Replace('\'',' ');

            string sql = " INSERT INTO Question (Title,Answer1,Answer2,Answer3,Answer4,Description,ExamType,ParentID,QuestionType,Answer,Analysis) VALUES" +
                "('" + title + "', '" + tbAnswer1.Text.Trim() + "', '" + tbAnswer2.Text.Trim() + "', '" + tbAnswer3.Text.Trim() + "', '" + tbAnswer4.Text.Trim() +
                "', '" + Description + "', '" + examType + "', '" + parentid + "', '" + questionType + "','" + txtAnswer.Text.Trim() + "','" + txtAnalysis.Text.Trim() + "');";
            int result = db.ExecuteNonQuery(sql);

            if (result > 0)
            {
                rtbTitle.Text = "";
                tbAnswer1.Text = "";
                tbAnswer2.Text = "";
                tbAnswer3.Text = "";
                tbAnswer4.Text = "";
                txtAnalysis.Text = "";
                txtAnswer.Text = "";
                MessageBox.Show("添加成功");
            }
            else
            {
                MessageBox.Show("添加失败");
            }
        }
    }
}
